package com.mgface.springcloud.client;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

/**
 * @author wanyuxiang
 * @version 1.0
 * @project springcloudCollection
 * @create 2018-08-16 14:22
 **/
@Component
public class RestTemplateClient {

    @Autowired
    public RestTemplate restTemplate;

    @HystrixCommand(fallbackMethod = "fallback", commandKey = "mgface", threadPoolProperties =
            {@HystrixProperty(name = "coreSize", value = "10")}) //commandKey熔断器的名称，默认为default，和配置文件对应
    public String say() {
        return restTemplate.getForObject("http://Service/hello?param=cloud", String.class);
    }

    public String fallback() {
        return "容错数据";
    }

}
